import {createRouter,createWebHashHistory,RouteRecordRaw} from "vue-router"
export const Layout = () => import('@/layout/index.vue');
import useStore from '@/store';



export const constantRoutes:Array<RouteRecordRaw> = [
    {
      path: '/redirect',
      component: Layout,
      meta: { hidden: true },
      children: [
        {
          path: '/redirect/:path(.*)',
          component: () => import('@/views/redirect/index.vue')
        }
      ]
    },
    {
        path:'/login',
        name:'登录',
        meta:{
          hidden:true,
          title:'登录'
        },
        component:()=>import("@/views/login/index.vue")
    },
    {
      path: '/',
      component: Layout,
      // redirect: '/dashboard',
      // meta:{}
      children: [
        {
          path: 'dashboard',
          component: () => import('@/views/dashboard/index.vue'),
          name: '首页',
          meta: { title: 'dashboard', icon: 'homepage', affix: true }
        },
        {
          path: '401',
          component: () => import('@/views/error-page/401.vue'),
          meta: { hidden: true }
        },
      ]
    }
]

const router = createRouter({
    history:createWebHashHistory(),
    routes:constantRoutes as RouteRecordRaw[],
    scrollBehavior:()=>({left:0,top:0})
})

export function resetRouter() {
  const { permission } = useStore();
  permission.routes.forEach(route => {
    const name = route.name;
    if (name && router.hasRoute(name)) {
      router.removeRoute(name);
    }
  });
}

export default router